// api.js

import axios from 'axios';



export const apiGet = async (url, params) => {
    try {
        const response = await axios.get(`${url}`, { params });
        return response.data;
    } catch (error) {
        throw new Error(error.response.data);
    }
};

export const apiPost = async (url, data) => {
    try {
        const response = await axios.post(`${url}`, data,{
            headers: {
              'Content-Type': 'application/json', // 设置 Content-Type 为 application/json
            },
          });
        return response.data;
    } catch (error) {
        throw new Error(error.response.data);
    }
};

export const apiFormPost = async (url, formData) => {
    try {
        const response = await axios.post(`${url}`, formData, {
            headers: {
              'Content-Type': 'multipart/form-data', // 设置 Content-Type 为 multipart/form-data
            },
          });
        return response.data;
    } catch (error) {
        throw new Error(error.response.data);
    }
};

export const apiFormGet = async (url) => {
    try {
        const response = await axios.get(`${url}`, {
            headers: {
              'Content-Type': 'multipart/form-data', // 设置 Content-Type 为 multipart/form-data
            },
          });
        return response.data;
    } catch (error) {
        throw new Error(error.response.data);
    }
};